
from django.shortcuts import render
from django.http import JsonResponse
from django.views import View
from users.models import User
import json
import re
from django.contrib.auth import login,authenticate, logout
import logging
logger = logging.getLogger("django")

from django_redis import get_redis_connection
from django.conf import settings
import pysnooper
from django.db.models import Q

# 用户信息
from django.contrib.auth.mixins import LoginRequiredMixin
from meiduo_mall.utils.views import LoginRequiredJSONMixin
from celery_tasks.email.tasks import send_verify_email
from meiduo_mall.utils.secret import SecretOauth
from users.utils import generate_verify_email_url
from carts.utils import merge_cart_cookie_to_redis





# Create your views here.
# 用户名是否重复的接口
class UsernameCountView(View):
    """用户名重复"""
    def get(self, request, username):

        # 提取参数
        # 参数校验
        # 数据处理
        try:
            count = User.objects.filter(username = username).count()
        except Exception as e:
            # 显示日志
            logger.info("数据库访问失败！！！")
            # 构建错误响应
            return JsonResponse({"code": 400,"errmsg": "数据库错误"})
        # 构建响应
        return JsonResponse({"code": 0,"errmsg": "ok","count": count})




# 手机号是否重复的接口
class MobileCountView(View):
    """手机号重复"""
    def get(self, request, mobile):

        try:
            count = User.objects.filter(mobile=mobile).count()

        except Exception as e:
            # 显示日志
            logger.info("数据库访问失败！！！")
            # 构建错误响应返回
            return JsonResponse({"code": 400,"errmsg": "数据库错误"})
        #　构建响应返回,前端根据返回的count去判断用户名是否重复
        return JsonResponse({"code": 0,"errmsg": "ok","count": count})




# 用户注册接口
class RegisterView(View):
    """用户注册"""
    def post(self, request):
        # 1.接收参数:接收请求体中的JSON数据用：request.body
        # 从请求体中获取原始的JSON数据，bytes类型的
        json_bytes = request.body
        # 将bytes类型的JSON数据，转成JSON字符串
        json_str = json_bytes.decode()
        # 将JSON字符串，转成python的标准字典
        json_dict = json.loads(json_str)

        # 必要
        username = json_dict.get("username")
        password = json_dict.get("password")
        password2 = json_dict.get("password2")
        mobile = json_dict.get("mobile")
        sms_code = json_dict.get("sms_code")
        # 非必要
        allow = json_dict.get("allow", False)
        # 2.校验参数
        # 必要性校验
        # 校验(整体参数是否为空)，当且仅当必要的参数都不为空，表示都传了
        if not all([username, password, password2, mobile, sms_code]):
            return JsonResponse({ "code": 400, "errmsg": "缺少必要参数！"})
        # 约束性校验
        # username检验
        if not re.match(r'^[a-zA-Z0-9_-]{5,20}$', username) or re.match(r'^\d{5,20}$', username):
            return JsonResponse({ "code": 400, "errmsg": "用户名格式有误！"})
        # password检验
        if not re.match(r'^[a-zA-Z0-9]{8,20}$', password):
            return JsonResponse({'code': 400, 'errmsg': '密码格式有误!' })
        # password2 和 password
        if password2!=password:
            return JsonResponse({ 'code': 400,  'errmsg': '两次输入的密码不一致！'})
        # mobile检验
        if not re.match(r'^1[3-9]\d{9}$', mobile):
            return JsonResponse({  "code": 400,  "errmsg": '手机号格式有误！'})
        # allow检验
        if not allow:
            return JsonResponse({ 'code': 400, 'errmsg': '没有勾选'})

        # 业务性校验－－短信验证码
        # TODO:此处填充短信验证码校验
        # 判断短信验证码是否正确：跟图形验证码的验证一样的逻辑
        # 提取服务端存储的短信验证码：以前怎么存储，现在就怎么提取
        redis_conn = get_redis_connection("verify_code")
        sms_code_from_redis = redis_conn.get("sms_%s" % mobile)
        # 判断短信验证码是否过期
        if not sms_code_from_redis:
            return JsonResponse({"code": 400, "errmsg": "短信验证码失效"})
        # 对比用户输入的和服务端存储的短信验证码是否一致
        if sms_code != sms_code_from_redis.decode():
            return JsonResponse({"code": 400, "errmsg": "短信验证码错误"})


        # 注册的核心逻辑-保存到数据库 (username password mobile)
        # 3.业务数据处理--新建用户模型类对象保存数据库，状态保持
        try:
            # create－－－－不会给密码加密
            # create_user－－－－会给密码加密
            # create_superuser()----密码加密，超级用户，要求传邮箱
            user = User.objects.create_user(
                username=username,
                password=password,
                mobile=mobile
            )
        except Exception as e:
            print("异常信息：", e)
            logger.error("注册用户，写入mysql失败！")
            return JsonResponse({
                "code": 400,
                "errmsg": "服务器繁忙，请稍后。"
            })

        # TODO: 用户状态保持
        #　1.用户信息写入session缓存,　2.在响应中添加session记录在cookie中
        login(request, user)


        # 4.构建响应
        response =  JsonResponse({"code": 0,"errmsg": "恭喜，注册成功！"})

        #把用户名添加到cookie中，前端从中取出用于展示
        response.set_cookie('username', user.username, max_age=3600*24*14)

        return response




# 用户登录接口
class LoginView(View):
    """用户登录"""
    # @pysnooper.snoop()
    def post(self, request):
        # 1.接收参数
        json_bytes = request.body
        json_str = json_bytes.decode()
        json_dict = json.loads(json_str)
        # 提取参数
        username = json_dict.get("username")
        password = json_dict.get("password")
        remembered = json_dict.get("remembered", False) # 记住登录

        # # 实现多账号登录
        # # 判断用户输入的账号是用户名还是手机号
        # if re.match(r'^1[3-9]\d{9}$', username):
        #     # 用户输入的账号是手机号:将USERNAME_FIELD指定为'mobile'字段,来控制过滤字段
        #     User.USERNAME_FIELD = 'mobile'
        # else:
        #     # 用户输入的账号是用户名:将USERNAME_FIELD指定为'username'字段
        #     User.USERNAME_FIELD = 'username'



        # 校验参数
        # 2.1必要性校验
        if not all([username, password]):
            return JsonResponse({"code": 400, "errmsg": "缺少必要参数"})

        # 2.2约束性校验
            # username检验
        if not re.match(r'^[a-zA-Z0-9_-]{5,20}$', username):
            return JsonResponse({"code": 400,"errmsg": "用户名格式有误！"})
            # password检验
        if not re.match(r'^[a-zA-Z0-9]{8,20}$', password):
            return JsonResponse({'code': 400,'errmsg': '密码格式有误!'})

        # 3.业务性校验:判断是否能登录
        # TODO:手动来验证
        # 3.1根据“用户名”查询用户模型类对象
        # try:
        #     # 中间打逗号是并且，逻辑错误
        #     # user = User.objects.get(username=username, mobile=username)
        #     # 用Ｑ对象实现或关系
        #     user = User.objects.get(Q(username=username) | Q(mobile=username))
        # except User.DoesNotExist as e:
        #     return JsonResponse({"code": 400, "errmsg": "用户名或者密码错误"})
        # # 3.2验证密码
        # if not user.check_password(password):
        #     return JsonResponse({"code": 400, "errmsg": "用户名或者密码错误"})

        # TODO:自动验证
        # 全局认证函数authenticate
        # 功能：根据username和password校验用户－－只支持用户名
        # 参数：用户名和密码
        # 成功返回用户对象，失败返回None
        user = authenticate(request, username=username, password=password)
        if user is None:
            return JsonResponse({"code": 400, "errmsg": "用户名或者密码错误"}, status=400)

        # 4.状态保持
        login(request, user)

        # 5.判断是否记住了用户
        if remembered != True:
            # 7.如果没有记住: session立即失效，关闭浏览器就失效
            request.session.set_expiry(0)

        else:
            # 6.如果记住:  session设置为两周有效
            request.session.set_expiry(None)



        # 构建响应
        response =  JsonResponse({"code": 0, "errmsg": "ok"})

        # TODO:在cookie中设置username记录登录用户用作前端页面展示,前端会在cookie中取出用户名用于展示
        response.set_cookie('username', user.username,  max_age=3600*24*14)

        # TODO:合并购物车
        merge_cart_cookie_to_redis(request, response)

        return response




# 用户退出登录接口
class LogoutView(LoginRequiredJSONMixin, View):
    """用户退出登录"""
    def delete(self, request):
        # 清除状态保持
        # 请求头中的cookie数据里保存有sessionid
        logout(request)

        response = JsonResponse({'code': 0, 'errmsg': 'ok'})
        # 把用来界面展示的username也删掉
        response.delete_cookie('username')

        return response




# 判断用户是否登录
# 前提条件：用户已经登录才能被调用
# LoginRequiredJSONMixin:只有用户登录才会执行视图函数，否则返回错误响应
class UserInfoView(LoginRequiredJSONMixin, View):
    """用户信息"""
    def get(self, request):
        # 怎么判断用户已经登录
        # request.user:如果已经登录，是User模型对象
        # 如果没登录，是AnonymousUser匿名分用户模型类对象
        user = request.user
        """提供个人信息界面"""
        # if user.is_authenticated:
        #     # 已经登录
        #     return JsonResponse({
        #         'code': 0,
        #         'errmsg': 'ok',
        #         "info_data": {
        #             "username": user.username,
        #             "mobile": user.mobile,
        #             "email": user.email,
        #             "email_active": 'true'}
        #     })
        # else:
        #     return JsonResponse({'code': 400, 'errmsg': '没有登录'})
        return JsonResponse({
            'code': 0,
            'errmsg': 'ok',
            "info_data": {
                "username": user.username,
                "mobile": user.mobile,
                "email": user.email,
                "email_active": user.email_active}
        })
# print(UserInfoView.__mro__)




# 更新保存邮箱
class EmailView(LoginRequiredJSONMixin, View):
    """添加邮箱"""
    def put(self, request):
        # 1.提取参数
        data = json.loads(request.body.decode())
        email = data.get('email')

        # 2.校验参数
        # 必要性校验
        if not email:
            return JsonResponse({'code': 400, 'errmsg': '邮箱为空'})
        # 约束性校验
        if not re.match('^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$', email):
            return JsonResponse({'code': 400, 'errmsg': '邮箱格式有误'})
        # 3.业务数据处理－－1.保存更新邮箱，2.发送验证邮件(业务性打校验)
        try:
            # user = User.objects.create_user(
            #     email=email
            # )
            user = request.user #django会用前端传来的sessionid去数据库取出这个用户对象的数据信息
            # user = User.objects.get(user = user)

            user.email = email
            user.save()
        except Exception as e:
            logger.error('数据库更新邮箱失败：%s' % e)
            return JsonResponse({'code': 400, 'errmsg': '数据库更新邮箱失败'})

        # TODO:发送验证邮件
        # verify_url = 'asdadasdfshgjhljkl'
        # 用定义好的函数替换原来的字符串:
        verify_url = generate_verify_email_url(request)
        # 用异步任务发送邮件
        send_verify_email.delay(email, verify_url)

        # 4.构建响应
        return JsonResponse({'code': 0, 'errmsg': 'ok'})




# 激活邮箱－－验证token
class VerifyEmailView(View):

    def put(self, request):

        # 提取参数
        token = request.GET.get('token')
        # 校验参数
        if not token:
            return JsonResponse({'code': 400, 'errmsg': '缺少token参数'})
        #　业务数据处理－－校验token有效性，激活邮箱
        # 解密token
        user_dict =SecretOauth().loads(token)
        user_id=user_dict.get('user_id')
        email=user_dict.get('email')
        try:
            user = User.objects.get(pk=user_id, email=email, is_active=True)
        except User.DoesNotExist as e:
            logger.info('用户不存在或者已经注销：%s' % e)
            return JsonResponse({'code': 400, 'errmsg': '用户不存在或者已经注销'})

        else:
            user.email_active = True
            user.save()

        # 构建响应
        return JsonResponse({'code': 400, 'errmsg': '邮箱验证成功'})




from .models import Address
# 新增用户收货地址
class CreateAddressView(LoginRequiredJSONMixin, View):

    def post(self, request):
        # 1.提取参数,前端传来
        json_dict = json.loads(request.body.decode())

        receiver = json_dict.get('receiver')

        province_id = json_dict.get('province_id')
        city_id = json_dict.get('city_id')
        district_id = json_dict.get('district_id')

        place = json_dict.get('place')
        mobile = json_dict.get('mobile')
        tel = json_dict.get('tel')
        email = json_dict.get('email')
        # 2.校验参数
        # 目前正在使用的地址不能超过20个，不包含注销的
        user = request.user  #用户模型类对象
        count = user.addresses.filter(is_deleted=False).count()
        if count >= 20:
            return JsonResponse({'code': 400, 'errmsg': '最多20个地址'})

        # 必要性校验，tel和email可以不填，其他都要填
        if not all([receiver, province_id, city_id, district_id, place, mobile]):
            return JsonResponse({'code': 400, 'errmsg': '缺少必要参数'})
        # 约束性校验
        if not re.match(r'^\w{1,20}$', receiver):
            return JsonResponse({'code': 400, 'errmsg': '收货人昵称有误'})
        if not re.match(r'^1[3-9]\d{9}$', mobile):
            return JsonResponse({'code': 400, 'errmsg': '参数mobile有误'})

        if tel:
            if not re.match(r'^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$', tel):
                return JsonResponse({'code': 400, 'errmsg': '参数tel有误'})
        if email:
            if not re.match(r'^[a-z0-9][\w\.\-]*@[a-z0-9\-]+(\.[a-z]{2,5}){1,2}$', email):
                return JsonResponse({'code': 400, 'errmsg': '参数email有误'})
        # 3.业务数据处理--新建Address对象，保存数据库
        try:
            # 看地址模型类需要哪些字段，就传哪些字段，将数据写入数据库
            address = Address.objects.create(
                user = request.user,
                province_id=province_id,
                city_id=city_id,
                district_id=district_id,
                title=receiver,# 由于新增地址接口没有传递标题，此处默认把标题设置为receiver
                receiver=receiver,
                place=place,
                mobile=mobile,
                tel=tel or '', # tel if tel else ''
                email=email or ''# 如果前端有传来email就写进去，没有就填入空
            )
            # 如果用户的default_address为空，把新增的收货地址设置为用户的默认收货地址
            user = request.user
            if not user.default_address:
                user.default_address=address
                user.save()

        except Exception as e:
            return JsonResponse({'code': 400, 'errmsg': '保存收货地址错误'})

        # 4.构建响应
        return JsonResponse({
            'code': 0,
            'errmsg': 'ok',
            'address': {
                'id': address.id,
                'title': address.title,
                'receiver': address.receiver,
                'province': address.province.name,
                'city': address.city.name,
                'district': address.district.name,
                'place': address.place,
                'mobile': address.mobile,
                'tel': address.tel,
                'email': address.email
            }
        })




# 展示收货地址--当前登录用户的多条地址收据列表返回
class AddressView(LoginRequiredJSONMixin, View):

    def get(self, request):

        #1.提取参数，前端没有传来参数
        # user = request.user
        #2.校验参数
        #3.业务数据处理
        # 获取所有的地址
        try:
            # addresses = Address.objects.filter(request.user=user, is_deleted=False)
            addresses = request.user.addresses.filter(is_deleted=False)
        except Exception as e:
            return JsonResponse({'code': 400, 'errmsg': '读取数据库错误'})
        # 创建空的列表
        address_dict_list=[]

        # 遍历
        for address in addresses:
            # 提前准备数据
            address_dict = {
                "id": address.id,
                "title": address.title,
                "receiver": address.receiver,
                "province": address.province.name,
                "city": address.city.name,
                "district": address.district.name,
                "place": address.place,
                "mobile": address.mobile,
                "tel": address.tel,
                "email": address.email
            }
            # 如果是默认地址
            if address.id == request.user.default_address.id:
                address_dict_list.insert(0,address_dict)
            else:
                address_dict_list.append(address_dict)
        # 获取默认地址id
        default_id = request.user.default_address_id
        #4.构建响应
        return JsonResponse({'code': 0, 'errmsg': 'ok', 'default_address_id': default_id, 'addresses': address_dict_list})




# 修改收货地址
# 删除收货地址
class UpdateDestroyAddressView(LoginRequiredJSONMixin, View):
    # 修改收货地址
    def put(self, request, address_id):
        # 1.提取参数
        user = request.user
        json_dict = json.loads(request.body.decode())
        receiver = json_dict.get('receiver')
        province_id = json_dict.get('province_id')
        city_id = json_dict.get('city_id')
        district_id = json_dict.get('district_id')
        place = json_dict.get('place')
        mobile = json_dict.get('mobile')
        tel = json_dict.get('tel')
        email = json_dict.get('email')

        # 2.校验参数
        count = user.addresses.filter(is_deleted=False).count()
        if count >= 20:
            return JsonResponse({'code': 400, 'errmsg': '最多20个地址'})

        # 必要性校验
        if not all([receiver, province_id, city_id, district_id, place, mobile]):
            return JsonResponse({'code': 40,'errmsg': '缺少必传参数'})
        # 约束性校验
        if not re.match(r'^1[3-9]\d{9}$', mobile):
            return JsonResponse({'code': 400,'errmsg': '参数mobile有误'})

        if tel:
            if not re.match(r'^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$', tel):
                return JsonResponse({'code': 400,'errmsg': '参数tel有误'})
        if email:
            if not re.match(r'^[a-z0-9][\w\.\-]*@[a-z0-9\-]+(\.[a-z]{2,5}){1,2}$', email):
                return JsonResponse({'code': 400,'errmsg': '参数email有误'})
        # 3.业务数据处理－－更新地址信息
        try:
            Address.objects.filter(id=address_id).update(
                user = request.user,
                title =receiver,
                receiver =receiver,
                province_id = province_id,
                city_id = city_id,
                district_id =district_id,
                place = place,
                mobile = mobile,
                tel = tel,
                email = email
            )
            # json_dict.pop('province')
            # json_dict.pop('city')
            # json_dict.pop('district')
            # 函数解包传参数－－把字典的键值对解包为关键字参数传入函数
            # Address.objects.filter(id=address_id).update(**json_dict)

        except Exception as e:
            return JsonResponse({'code': 400, 'errmsg': '更新收货地址失败'})


        # 4.构建响应
        address = Address.objects.get(pk=address_id)
        address_dict ={
            "id": address.id,
            "title": address.title,
            "receiver": address.receiver,
            "province": address.province.name,
            "city": address.city.name,
            "district": address.district.name,
            "place": address.place,
            "mobile": address.mobile,
            "tel": address.tel,
            "email": address.email
        }
        return JsonResponse({
            'code': 0,
            'errmsg': 'ok',
            'address': address_dict
        })

    # 删除收货地址
    def delete(self, request, address_id):

        # 1.提取参数
        user = request.user
        # 2.校验参数
        # 3.业务数据处理--逻辑删除
        try:
            address = Address.objects.get(id=address_id, is_deleted=False)
            # address = Address.objects.get(pk=address_id, is_deleted=False)
            address.is_deleted = True
            address.save()

            # 如果删除的是默认地址，就把用户最新更新的地址设置为默认地址
            if address.id == user.default_address.id:
                addresses = Address.objects.filter(user=user, is_deleted=False).order_by('-update_time')
                # 如果有，用户默认地址为最新的那个地址
                if addresses:
                    user.default_address = addresses[0]
                # 如果一个地址也没有，默认地址为空
                else:
                    user.default_address = None
                user.save()
        except Exception as e:
            logger.info(e)
            return JsonResponse({'code': 400, 'errmsg': '删除地址失败'})


        # 4.构建响应
        return JsonResponse({'code': 0, 'errmsg': 'ok'})






# 设置默认收货地址
class DefaultAddressView(LoginRequiredJSONMixin, View):

    def put(self, request, address_id):
        #　1.提取参数
        user = request.user
        # 2.校验参数
        # 3.业务数据处理
        try:
            address = Address.objects.get(id=address_id, is_deleted=False)
            user.default_address = address
            user.save()
        except Exception as e:
            return JsonResponse({'code': 400, 'errmsg': '地址失效'})
        # 4.构建响应
        return JsonResponse({'code': 0, 'errmsg': 'ok'})







# 修改地址标题
class UpdateTitleAddressView(LoginRequiredJSONMixin, View):

    def put(self, request, address_id):

        #　1.提取参数
        user = request.user
        json_dict = json.loads(request.body.decode())
        title=json_dict.get('title')
        # 2.校验参数
        if not title:
            return JsonResponse({'code': 400, 'errmsg': '缺少必要参数'})
        if not re.match(r'^\w{1,20}$', title):
            return JsonResponse({'code': 400, 'errmsg': '标题格式错误'})
        # 3.业务数据处理
        try:
            address = Address.objects.get(id=address_id, is_deleted=False)
            address.title = title
            address.save()
        except Exception as e:
            return JsonResponse({'code': 400, 'errmsg': '更新标题失败'})
        # 4.构建响应
        return JsonResponse({'code': 0, 'errmsg': 'ok'})





# 修改密码
class ChangePasswordView(LoginRequiredJSONMixin, View):

    def put(self, request):

        #　1.提取参数
        user = request.user
        json_dict = json.loads(request.body.decode())
        old_password = json_dict.get('old_password')
        new_password = json_dict.get('new_password')
        new_password2 = json_dict.get('new_password2')

        # 2.校验参数
        if  not user.check_password(old_password):
            return JsonResponse({'code': 400, 'errmsg': '密码输入错误'})
        if not all([old_password, new_password, new_password2]):
            return JsonResponse({'code': 400, 'errmsg': '缺少必要参数'})
        if not re.match(r'^[a-zA-Z0-9]{8,20}$', new_password):
            return JsonResponse({'code': 400, 'errmsg': '新密码格式有误'})
        if new_password != new_password2:
            return JsonResponse({'code': 400, 'errmsg': '新密码两次输入不一致'})
        if new_password == old_password:
            return JsonResponse({'code': 400, 'errmsg': '新旧密码一样'})
        # 3.业务数据处理
        # user.password = new_password
        user.set_password(new_password)
        user.save()
        # 在request里面提取cookie删掉
        logout(request)
        # 4.构建响应
        response = JsonResponse({'code': 0, 'errmsg': 'ok'})

        response.delete_cookie('username')

        return response


from goods.models import SKU,GoodsVisitCount
from django.utils import timezone
class UserBrowseHistory(LoginRequiredJSONMixin,View):

    # 用户浏览记录
    def post(self, request):
        """保存用户浏览记录"""
        # 1.提取参数
        user = request.user
        json_dict = json.loads(request.body.decode())
        sku_id = json_dict.get('sku_id')
        # 2.校验参数
        # 业务性校验
        try:
            sku =SKU.objects.get(pk=sku_id, is_launched=True)
        except Exception as e:
            return JsonResponse({'code': 400, 'errmsg': 'sku商品失效'})
        # 3.业务数据处理--存入redis

        redis_conn = get_redis_connection('history')
        p = redis_conn.pipeline()
        # 去重
        p.lrem('history_%s' % user.id, 0, sku_id)
        # 写入
        p.lpush('history_%s' % user.id, sku_id)
        # 切片，只要５个
        p.ltrim('history_%s' % user.id, 0, 4)
        # 启动管道
        p.execute()




        # TODO: 记录当前sku_id商品分类访问量
        cur_0_time = timezone.localtime().replace(hour=0, minute=0, second=0)
        category = sku.category
        # 根据category分类和当日的0时刻，过滤出GoodsVistCount访问量对象
        try:
            visit = GoodsVisitCount.objects.get(
                category=category,
                create_time__gte = cur_0_time
            )
        except GoodsVisitCount.DoesNotExist as e:
            # 不存在就新建
            visit = GoodsVisitCount.objects.create(
                category=category,
                count = 1
            )
        else:
            # 存在则累加
            visit.count += 1
            visit.save()





        # 4.构建响应
        return JsonResponse({'code': 0, 'errmsg': 'ok'})


    # 查询用户浏览记录
    def get(self, request):

        # 1.提取参数
        user = request.user
        # 2.校验参数
        # 3.业务数据处理--查询redis

        redis_conn =get_redis_connection('history')
        skus_id = redis_conn.lrange('history_%s' % user.id, 0, -1)

        skus = []
        for sku_id in skus_id:
            sku =SKU.objects.get(pk=sku_id, is_launched=True)
            skus.append({
                'id': sku.id,
                'name': sku.name,
                'default_image_url': sku.default_image.url,
                'price': sku.price
            })

        # 4.构建响应
        return JsonResponse({
            'code': 0,
            'errmsg': 'ok',
            'skus': skus
        })